package org.dromara.system.controller.system;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.system.domain.vo.MachineModelVo;
import org.dromara.system.domain.bo.MachineModelBo;
import org.dromara.system.service.IMachineModelService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 机器型号
 *
 * @author Lion Li
 * @date 2025-07-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/model")
public class MachineModelController extends BaseController {

    private final IMachineModelService machineModelService;

    /**
     * 查询机器型号列表
     */
//    @SaCheckPermission("system:model:list")
    @GetMapping("/list")
    public TableDataInfo<MachineModelVo> list(MachineModelBo bo, PageQuery pageQuery) {
        return machineModelService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出机器型号列表
     */
//    @SaCheckPermission("system:model:export")
    @Log(title = "机器型号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MachineModelBo bo, HttpServletResponse response) {
        List<MachineModelVo> list = machineModelService.queryList(bo);
        ExcelUtil.exportExcel(list, "机器型号", MachineModelVo.class, response);
    }

    /**
     * 获取机器型号详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("system:model:query")
    @GetMapping("/{id}")
    public R<MachineModelVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(machineModelService.queryById(id));
    }

    /**
     * 新增机器型号
     */
//    @SaCheckPermission("system:model:add")
    @Log(title = "机器型号", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MachineModelBo bo) {
        return toAjax(machineModelService.insertByBo(bo));
    }

    /**
     * 修改机器型号
     */
//    @SaCheckPermission("system:model:edit")
    @Log(title = "机器型号", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MachineModelBo bo) {
        return toAjax(machineModelService.updateByBo(bo));
    }

    /**
     * 删除机器型号
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("system:model:remove")
    @Log(title = "机器型号", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(machineModelService.deleteWithValidByIds(List.of(ids), true));
    }
}
